var Admin_Permission = function () {

    return {
        init: function () {
            var moduleactionid;
            var current_td;
                
            $('td a.yellow-stripe').click(function () {
                
                current_td = $(this).parent();
                moduleactionid = $(current_td).parent().attr('moduleactionid');
                
                if ($(this).hasClass('group')) {
                    actionid = 'get_group_permission';
                }
                else if ($(this).hasClass('user')) {
                    actionid = 'get_user_permission';
                }
                
                $.get('admin_passport_permission_execute.php', {
                    'action': actionid, 
                    'moduleactionid': moduleactionid
                },function (response) {
                
                    if (response.code != 200) {
                        return false;
                    }
                        
                    $('#responsive')
                    .find('select').html(tmpl( 'item-tmpl', response)).trigger("liszt:updated").end()
                    .find('input:hidden[name="moduleactionid"]').val(response.moduleactionid).end()
                    .find('input:hidden[name="permissionfortype"]').val(response.permissionfortype).end()
                    .modal();
                },
                'json');
            });
                
            $('#responsive').find('.btn-save').click(function () {
                    
                var obj = {};
                var tmp_inputs = $("input:hidden", $('#responsive'));
                
                $('div.result', $(current_td)).html('<img src="assets/img/loading.gif"/>')
                    
                $.map(tmp_inputs, function(n, i) {
                    
                    obj[$(n).attr('name')] = $(n).val();
                });
                    
                obj['permissionfor'] = $("select", $('#responsive')).val();
                    
                $.ajax({
                    url: 'admin_passport_permission_execute.php?action=update-permission',
                    type: 'post',
                    dataType: 'json',
                    data: $.param(obj),
                    success:function(response){
                            
                        if (response.code = 200) {
                            $('div.result', $(current_td)).html(response.data)
                        }
                    }
                });
                    
                $('.close','#responsive').click();
            });
        }
    };
}();